define(function (require, exports, module) {
    var $ = require("zepto");
    require("ylMap");
    var global = require("global");
    var page = require("page");
    var media = require("media");
    var map = {
        _map: $(".ylmap"),
        _mapValue: null,
        _mapIndex: null,
        mapAddEventHandler: function (t, e, n, i) {
            var a = n;
            global._isOwnEmpty(i) || (a = function () {
                n.call(this, i);
            });
            t.each(function () {
                $(this).on(e, a);
            });
        },
        mapShow: function (option) {
            var str_data = $(this).attr("data-detal");
            option.detal = "" !== str_data ? eval("(" + str_data + ")") : "";
            option.latitude = $(this).attr("data-latitude");
            option.longitude = $(this).attr("data-longitude");
            var detal = option.detal;
            var latitude = option.latitude;
            var longitude = option.longitude;
            var fnOpen = option.fnOpen;
            var fnClose = option.fnClose;
            global._scrollStop();
            map._map.addClass("show");
            $(document.body).animate({scrollTop: 0}, 0);
            if ($(this).attr("data-mapIndex") !== map._mapIndex) {
                map._map.html($('<div class="bk"><span class="css_sprite01 s-bg-map-logo"></span></div>'));
                map._mapValue = false;
                map._mapIndex = $(this).attr("data-mapIndex");
            } else {
                map._mapValue = true;
            }
            setTimeout(function () {
                if (map._map.find("div").length >= 1) {
                    map._map.addClass("mapOpen");
                    page.page_stop();
                    global._scrollStop();
                    media._audioNode.addClass("z-low");
                    page._page.eq(page._pageNow).css("z-index", 15);
                    setTimeout(function () {
                        map._mapValue || map.addMap(detal, latitude, longitude, fnOpen, fnClose);
                    }, 500);
                }
            }, 100);
        },
        mapSave: function () {
            $(window).on("webkitTransitionEnd transitionend", function () {
                map._map.removeClass("show");
                $(window).off("webkitTransitionEnd transitionend");
            });
            page && page.page_start();
            global._scrollStart();
            map._map.removeClass("mapOpen");
            media && media._audioNode.removeClass("z-low");
            map._mapValue || (map._mapValue = !0);
        },
        addMap: function (t, e, n, i, a) {
            var e = Number(e);
            var n = Number(n);
            var i = "function" === typeof i ? i : "";
            var a = "function" === typeof a ? a : "";
            var option = {sign_name: "", contact_tel: "", address: "天安门"};
            var t = global._isOwnEmpty(t) ? option : t;
            e = e ? e : 39.915;
            n = n ? n : 116.404;
            map._map.ylmap({detal: t, latitude: e, longitude: n, fnOpen: i, fnClose: a});
        }};
    return map;
});